{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0af5ba20",
   "metadata": {},
   "outputs": [],
   "source": [
    "from gs_quant.instrument import IRSwaption\n",
    "from gs_quant.markets.portfolio import Portfolio\n",
    "from gs_quant.session import Environment, GsSession\n",
    "from gs_quant.common import PayReceive, Currency"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d5bf201e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# external users should substitute their client id and secret; please skip this step if using internal jupyterhub\n",
    "GsSession.use(Environment.PROD, client_id=None, client_secret=None, scopes=('run_analytics',))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6ea95f36",
   "metadata": {},
   "source": [
    "### Reference other leg properties in instrument fields\n",
    "This would be the equivalent of making two requests to resolve the legs serialially\n",
    "```python\n",
    "swaption_1y5y = IRSwaption( ... )\n",
    "swaption_1y4y = IRSwaption( ... )\n",
    "\n",
    "swaption_1y5y.resolve()\n",
    "swaption_1y4y.strike = swaption_1y5y.strike\n",
    "swaption_1y4y.resolve()\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "96cac46c",
   "metadata": {},
   "outputs": [],
   "source": [
    "swaption_1y5y = IRSwaption(PayReceive.Pay, '5y', Currency.EUR, expiration_date='1y', strike=\"atm\", name=\"foo\")\n",
    "swaption_1y4y = IRSwaption(\n",
    "    PayReceive.Pay, '4y', Currency.EUR, expiration_date='1y', strike=\"=[foo].strike + 5bp\", name=\"bar\"\n",
    ")\n",
    "port = Portfolio((swaption_1y5y, swaption_1y4y))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "00f45d28",
   "metadata": {},
   "outputs": [],
   "source": [
    "port.resolve()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c0913ba1",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(port['foo'].strike * 1e4)\n",
    "print(port['bar'].strike * 1e4)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
